<?php


function catSelect($cat,$curId,$level){
	$str = "";
	$space = "";
	for($i=0;$i<$level;$i++){
		$space .= "&nbsp;";
	}
	$space .= $level?"|-":"";
	if(is_array($cat)){
		foreach($cat as $id=>$val){
			$selected = $curId == $id?"selected":"";
			$str .= "<option value='$id' $selected>$space{$val['name']}</option>";
			$str .= catSelect($val['child'], $curId,$level+1);
		}
	}
	return $str;
}

if(!function_exists("categoryList")){
	function categoryList($cat,$curId,$level){
		$str = "";
		$space = "";
		for($i=0;$i<$level;$i++){
			$space .= "&nbsp;&nbsp;&nbsp;&nbsp;";
		}
		$space .= $level?"|-":"";
		if(is_array($cat)){
			foreach($cat as $id=>$val){
				$selected = $curId == $id?"selected":"";			
				$str .= "<tr>";
				$str .= "<td>$space{$val['name']}</td>";
				$str .= "<td align='center'>{$val['sort_order']}</td>";
				$str .= "<td align='center'>";
				$str .= "<a href='./index.php?c=category&a=edit&id={$val["id"]}'>编辑</a> ";
				$str .= "<a href='javascript:del({$val["id"]});'>删除</a>";
				$str .= "<img src='./public/images/empty.gif' width='16' height='16' border='0' />";
				$str .= "</td>";
				$str .= "</tr>";
				$str .= categoryList($val['child'], $curId,$level+1);
			}
		}
		return $str;
	}
}